package com.example.threadActiveness;

import lombok.extern.slf4j.Slf4j;

/**
 * @author
 * 死锁
 */
@Slf4j
public class DeadLockTest {

    private static String a = "a";
    private static String b = "b";

    public static void main(String[] args) {
        Thread threadA = new Thread(()->{
            synchronized (a) {
                log.debug("threadA进入a同步块，执行中...");
//                try {
//                    //Thread.sleep(2000);   条件队列作用： 打破死锁的循环
//                    a.wait(5000);
//
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
                synchronized (b) {
                    log.debug("threadA进入b同步块，执行中...");
                }
            }
        },"threadA");

        Thread threadB = new Thread(()->{
            synchronized (b) {
                log.debug("threadB进入b同步块，执行中...");
//                try {
//                    //b.wait(5000);
//                    Thread.sleep(2000);
//
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
                synchronized (a) {
                    log.debug("threadB进入a同步块，执行中...");
                }

            }
        },"threadB");

        threadA.start();
        threadB.start();

    }

}
